solving equations with quadratic form